#!/bin/bash

workspace_dir="/home/jenkins/workspace"

# 判断工作目录是否存在
if [ ! -d "$workspace_dir" ]; then
    echo "Workspace directory $workspace_dir 不存在或不是一个目录"
    exit 1
fi

# 获取workspace目录下所有子目录
subdirs=$(find "$workspace_dir" -mindepth 1 -maxdepth 1 -type d)

# 遍历每个子目录
for subdir in $subdirs; do
    # 获取子目录的名称
    subdir_name=$(basename "$subdir")
    
    # 检查子目录名称是否以tmp结尾、data开头
    if [[ ! "$subdir_name" =~ tmp$ ]] && [[ "$subdir_name" =~ ^data ]]; then
        echo "$subdir_name"
        sh copy-each.sh "/home/jenkins/workspace/$subdir_name" "/home/code/data"
    fi
done

